package com.briup.mt.service.impl;


import com.briup.mt.bean.Comment;
import com.briup.mt.bean.CommentExample;
import com.briup.mt.service.ICommentService;
import com.briup.mt.dao.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import java.util.List;

/**
 * @program: app03
 * @description: 账户实现类
 * @author: charles
 * @create: 2020-12-14 15:46
 **/
@Service


public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<Comment> query(String status) {
        //模板
        CommentExample example = new CommentExample();
        if (!StringUtils.isEmpty(status)){
            example.createCriteria().andStatusEqualTo(status);
        }

        List<Comment> list = commentMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Comment comment) {
        //如果base_User中存在id属性，表示更新；否则保存
        if (comment.getId()==null){
            commentMapper.insert(comment);
        }else{
            commentMapper.updateByPrimaryKey(comment);
        }
    }



    @Override
    public void deleteById(long id) {
        commentMapper.deleteByPrimaryKey(id);
    }


}
